(function() {

	var appModule = angular.module('tracecashModule');

	appModule.controller('AgreementListCtrl', ['$scope', '$rootScope', '$routeParams', '$http', '$modal', '$translate', function($scope, $rootScope, $routeParams, $http, $modal, $translate) {
		$scope.searchResults = {};
		$scope.setPage  = function(page) {
			$scope.currentPage = page;
			$http.get($rootScope.REST_PATH + '/agreement/search', {
				params : {
					p : $scope.currentPage,
					n : $rootScope.PAGE_SIZE
				}
			}).success(function(data) {
				$scope.searchResults = data;
			});
		};
		$scope.setPage(1);
		$scope.remove = function(agreement) {
			$translate('confirmDialog').then(function(text) {
				if (window.confirm(text)) {
					$http({
						method : 'DELETE',
						url : $rootScope.REST_PATH + '/agreement/remove/' + agreement.id
					}).success(function(data) {
						$scope.message = data;
						$scope.setPage(1);
					});
				}
			});
		};
		$scope.add = function() {
			$scope.open({});
		};
		$scope.edit = function(agreement) {
			$scope.open(agreement);
		};
		$scope.open = function(agreement) {
			var modalInstance = $modal.open({
				templateUrl : 'html/administration/agreement-detail.html',
				controller : 'AgreementDetailCtrl',
				size : 'lg',
				resolve : {
					agreement : function() {
						return agreement;
					}
				}
			});
			modalInstance.result.then(function(data) {
				$scope.message = data;
				$scope.setPage(1);
			}, function() {
			});
		};
	}]);
	
	appModule.controller('AgreementDetailCtrl', ['$scope', '$rootScope', '$http', '$modalInstance', 'agreement', function($scope, $rootScope, $http, $modalInstance, agreement) {
		$scope.agreement = agreement;
		$scope.save = function() {
			$http.post($rootScope.REST_PATH + '/agreement/save', $scope.agreement).success(function(data) {
				if (data.code == $rootScope.CODE_SUCCESS) {
					$modalInstance.close(data);
				} else {
					$scope.message = data;
				}
			});
		};
		$scope.cancel = function() {
			$modalInstance.dismiss('cancel');
		};
	}]);
	
	appModule.controller('WarrantyTypeListCtrl', ['$scope', '$rootScope', '$routeParams', '$http', '$modal', '$translate', function($scope, $rootScope, $routeParams, $http, $modal, $translate) {
		$scope.searchResults = {};
		$scope.setPage  = function(page) {
			$scope.currentPage = page;
			$http.get($rootScope.REST_PATH + '/warrantyType/search', {
				params : {
					p : $scope.currentPage,
					n : $rootScope.PAGE_SIZE
				}
			}).success(function(data) {
				$scope.searchResults = data;
			});
		};
		$scope.setPage(1);
		$scope.add = function() {
			$scope.open({});
		};
		$scope.edit = function(warrantyType) {
			$scope.open(warrantyType);
		};
		$scope.open = function(warrantyType) {
			var modalInstance = $modal.open({
				templateUrl : 'html/administration/warranty-type-detail.html',
				controller : 'WarrantyTypeDetailCtrl',
				size : 'lg',
				resolve : {
					warrantyType : function() {
						return warrantyType;
					}
				}
			});
			modalInstance.result.then(function(data) {
				$scope.message = data;
				$scope.setPage(1);
			}, function() {
			});
		};
	}]);

	appModule.controller('WarrantyTypeDetailCtrl', ['$scope', '$rootScope', '$http', '$modalInstance', 'warrantyType', function($scope, $rootScope, $http, $modalInstance, warrantyType) {
		$scope.warrantyType = warrantyType;
		$scope.save = function() {
			$http.post($rootScope.REST_PATH + '/warrantyType/save', $scope.warrantyType).success(function(data) {
				if (data.code == $rootScope.CODE_SUCCESS) {
					$modalInstance.close(data);
				} else {
					$scope.message = data;
				}
			});
		};
		$scope.cancel = function() {
			$modalInstance.dismiss('cancel');
		};
	}]);
	
	appModule.controller('CompanyListCtrl', ['$scope', '$rootScope', '$routeParams', '$http', '$modal', '$translate', function($scope, $rootScope, $routeParams, $http, $modal, $translate) {
		$scope.searchResults = {};
		$scope.setPage  = function(page) {
			$scope.currentPage = page;
			$http.get($rootScope.REST_PATH + '/company/search', {
				params : {
					p : $scope.currentPage,
					n : $rootScope.PAGE_SIZE
				}
			}).success(function(data) {
				$scope.searchResults = data;
			});
		};
		$scope.setPage(1);
		$scope.add = function() {
			$scope.open({});
		};
		$scope.edit = function(company) {
			$scope.open(company);
		};
		$scope.open = function(company) {
			var modalInstance = $modal.open({
				templateUrl : 'html/administration/company-detail.html',
				controller : 'CompanyDetailCtrl',
				size : 'lg',
				resolve : {
					company : function() {
						return company;
					}
				}
			});
			modalInstance.result.then(function(data) {
				$scope.message = data;
				$scope.setPage(1);
			}, function() {
			});
		};
	}]);
	
	appModule.controller('CompanyDetailCtrl', ['$scope', '$rootScope', '$http', '$modalInstance', 'company', function($scope, $rootScope, $http, $modalInstance, company) {
		$scope.company = company;
		$scope.save = function() {
			$http.post($rootScope.REST_PATH + '/company/save', $scope.company).success(function(data) {
				if (data.code == $rootScope.CODE_SUCCESS) {
					$modalInstance.close(data);
				} else {
					$scope.message = data;
				}
			});
		};
		$scope.cancel = function() {
			$modalInstance.dismiss('cancel');
		};
	}]);
	
	appModule.controller('MailRecipientListCtrl', ['$scope', '$rootScope', '$routeParams', '$http', '$modal', '$translate', function($scope, $rootScope, $routeParams, $http, $modal, $translate) {
		$scope.searchResults = {};
		$scope.setPage  = function(page) {
			$scope.currentPage = page;
			$http.get($rootScope.REST_PATH + '/mailRecipient/search', {
				params : {
					p : $scope.currentPage,
					n : $rootScope.PAGE_SIZE
				}
			}).success(function(data) {
				$scope.searchResults = data;
			});
		};
		$scope.setPage(1);
		$scope.add = function() {
			$scope.open({});
		};
		$scope.edit = function(mailRecipient) {
			$scope.open(mailRecipient);
		};
		$scope.open = function(mailRecipient) {
			var modalInstance = $modal.open({
				templateUrl : 'html/administration/email-detail.html',
				controller : 'MailRecipientDetailCtrl',
				size : 'lg',
				resolve : {
					mailRecipient : function() {
						return mailRecipient;
					}
				}
			});
			modalInstance.result.then(function(data) {
				$scope.message = data;
				$scope.setPage(1);
			}, function() {
			});
		};
	}]);
	
	appModule.controller('MailRecipientDetailCtrl', ['$scope', '$rootScope', '$http', '$modalInstance', 'mailRecipient', function($scope, $rootScope, $http, $modalInstance, mailRecipient) {
		$scope.mailRecipient = mailRecipient;
		$scope.save = function() {
			$http.post($rootScope.REST_PATH + '/mailRecipient/save', $scope.mailRecipient).success(function(data) {
				if (data.code == $rootScope.CODE_SUCCESS) {
					$modalInstance.close(data);
				} else {
					$scope.message = data;
				}
			});
		};
		$scope.cancel = function() {
			$modalInstance.dismiss('cancel');
		};
	}]);

	appModule.controller('AgreementWarrantyTypeListCtrl', ['$scope', '$rootScope', '$routeParams', '$http', '$modal', '$translate', function($scope, $rootScope, $routeParams, $http, $modal, $translate) {
		$scope.searchResults = {};
		$scope.setPage  = function(page) {
			$scope.currentPage = page;
			$http.get($rootScope.REST_PATH + '/agreementWarrantyType/search', {
				params : {
					p : $scope.currentPage,
					n : $rootScope.PAGE_SIZE
				}
			}).success(function(data) {
				$scope.searchResults = data;
			});
		};
		$scope.setPage(1);
		$scope.add = function() {
			$scope.open({});
		};
		$scope.edit = function(agreementWarrantyType) {
			$scope.open(agreementWarrantyType);
		};
		$scope.open = function(agreementWarrantyType) {
			var modalInstance = $modal.open({
				templateUrl : 'html/administration/agreement-warranty-type-detail.html',
				controller : 'AgreementWarrantyTypeDetailCtrl',
				size : 'lg',
				resolve : {
					agreementWarrantyType : function() {
						return agreementWarrantyType;
					}
				}
			});
			modalInstance.result.then(function(data) {
				$scope.message = data;
				$scope.setPage(1);
			}, function() {
			});
		};
	}]);
	
	appModule.controller('AgreementWarrantyTypeDetailCtrl', ['$scope', '$rootScope', '$http', '$modalInstance', 'agreementWarrantyType', function($scope, $rootScope, $http, $modalInstance, agreementWarrantyType) {
		$scope.agreementWarrantyType = agreementWarrantyType;
		$scope.save = function() {
			$http.post($rootScope.REST_PATH + '/agreementWarrantyType/save', $scope.agreementWarrantyType).success(function(data) {
				if (data.code == $rootScope.CODE_SUCCESS) {
					$modalInstance.close(data);
				} else {
					$scope.message = data;
				}
			});
		};
		$scope.cancel = function() {
			$modalInstance.dismiss('cancel');
		};
	}]);

	appModule.controller('SubcompanyListCtrl', ['$scope', '$rootScope', '$routeParams', '$http', '$modal', '$translate',function($scope, $rootScope, $routeParams, $http, $modal, $translate) {

	}]);
	
	appModule.controller('NetworkListCtrl', ['$scope', '$rootScope', '$routeParams', '$http', '$modal', '$translate', function($scope, $rootScope, $routeParams, $http, $modal, $translate) {

	}]);

})();